package com.tian.controller;

import com.tian.pojo.Advisory;
import com.tian.pojo.Doctor;
import com.tian.service.AdvisoryService;
import com.tian.service.DoctorService;
import com.tian.vo.PageResult;
import com.tian.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

    @RestController
    @CrossOrigin
    @RequestMapping("/advisory")
    public class AdvisoryController {


        @Autowired
        private AdvisoryService doctorService;

        @GetMapping("/getadvisoryList")
        public SysResult getDoctorList(PageResult pageResult){
            pageResult = doctorService.getDoctorList(pageResult);
            return SysResult.success(pageResult);
        }

      /*  @DeleteMapping("/deleteDoctorById")
        public SysResult deleteUserById (Integer id){
            doctorService.deleteUserById(id);
            return SysResult.success();
        }

        @PostMapping("/saveDoctor")
        @Transactional  // 1.运行期异常 2.编译异常(检查异常)
        // 事务默认的条件下只对运行时异常有效
        public SysResult addUser(@RequestBody Doctor doctor){
            if (doctor.getBygood()==""||doctor.getAge()<=0||doctor.getDepartment()==""||doctor.getName()==""||doctor.getSex()=="")
                return SysResult.fail();
            doctorService.saveDoctor(doctor);
            return SysResult.success();
        }

        @PutMapping("/updateDoctor")
        public SysResult putDoctorList(@RequestBody Doctor doctor){
            doctorService.putDoctorList(doctor);

            return SysResult.success();
        }

        @GetMapping("/{id}")
        public SysResult getById(@PathVariable Integer id){
            return SysResult.success(doctorService.getById(id));
        }*/

    }
